$(function() {
	_addChangeListener("#floor_select", function() {
		var option = $('#floor_select option:selected');
		if(view && view.data) {view.data.floorName = option.text();}
		
		var floorId = $('#floor_select').val();
		if(load_room_select_by_floorId) {
			load_room_select_by_floorId(floorId);
		}
		
		if(load_bed_by_floorId) {
			load_bed_by_floorId(floorId);
		}
	});
	
	_addChangeListener("#floor_cond_select", function() {
		var floorId = $('#floor_cond_select').val();
		if(load_room_cond_select_by_floorId) {
			load_room_cond_select_by_floorId(floorId);
		}
		
		if(load_room_by_floorId) {
			load_room_by_floorId(floorId);
		}
	});
});

load_floor_select_by_buildingId = function(buildingId) {
	if($('#floor_select').length==0) {return;}

	$('#floor_select').html('<option value="" selected></option>');
	$('#room_select').html('<option value="" selected></option>');
	$('#bed_select').html('<option value="" selected></option>');
	
	var loginedUser = getLoginedUser();
	if(!buildingId || buildingId=='') {return;}

	find_basic_by_json(path+'/floor/find', {buildingId: buildingId}, function(response) {
		for(var i=0; i<response.data.length; i++) {
			$('#floor_select').append('<option value="' + response.data[i].floorId
				+ '">' + response.data[i].floorName + '</option>');
		}
	});
}

load_floor_cond_select_by_buildingId = function(buildingId) {
	if($('#floor_cond_select').length==0) {return;}

	$('#floor_cond_select').html('<option value="" selected></option>');
	$('#room_cond_select').html('<option value="" selected></option>');
	$('#bed_cond_select').html('<option value="" selected></option>');
	$('#vue_vm_list div').hide();
	
	var loginedUser = getLoginedUser();
	if(!buildingId || buildingId=='') {return;}

	find_basic_by_json(path+'/floor/find', {buildingId: buildingId}, function(response) {
		for(var i=0; i<response.data.length; i++) {
			$('#floor_cond_select').append('<option value="' + response.data[i].floorId
				+ '">' + response.data[i].floorName + '</option>');
		}
	});
}